package daoClasses;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import beanClasses.IndividualUser;
import connection.DBConnection;

public class LoginDAO 
{
	Connection con=null;
	Query q=new Query();
	String uname1;
	String password1;
	public String Chk_Authenticity(IndividualUser iu)
	{
		String status=null;
		String uname=iu.getAcc_holder_id();
    	String password = iu.getPwd();
    	 ResultSet rs = null;
		 PreparedStatement pstmt = null;
		 Statement stat=null;
		    try
		    {
		    	con = DBConnection.createConnection();
		    	//pstmt = con.prepareStatement(q.loginUser(iu));
		    	stat=con.createStatement();
		    	rs=stat.executeQuery("select Acc_holder_id,pwd from Acc_Holder");
		    	boolean result=rs.next();
		    	System.out.println("result= "+rs);
		    	while(rs.next())
		    	{
		    		uname1=rs.getString("Acc_holder_id");
		    		password1 =rs.getString("pwd");
		    		System.out.println("Your user name is " + uname);
		    		
		    		if((!uname1.equals(uname)) || (!password1.equals(password) ))
		    		{
		    			status="Invalid";
		    		}
		    		else{
		    			status="success";
		    		}
		    		if(status.equals("success"))
		    			break;
		    	}
		    }
		    	catch(SQLException e)
		    	{
		    		e.printStackTrace();
		    	}
		    	return status;
		    }
	}